#!/usr/bin/python2.7
#
# Copyright 2011 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from django.template import loader
from third_party.active_state.recipes.autoassign import autoassign
import django.template

'''
Created on Dec 11, 2011

@author: ibrahimelfar
'''

class CustomCommandScheme:
    @autoassign
    def __init__(self, language, command_sets = {}, variable_lists = {}): pass

class CommandSet:
    @autoassign
    def __init__(self, command_set_type, module, commands = []): pass

class Command:
    @autoassign
    def __init__(self, name, group, states, command_template_name, pattern_name): pass

class VariableList:
    @autoassign
    def __init__(self, name, values = []): pass

def generate_configuration(language_modules, environment_modules):
    schemes = {}
    for language in language_modules:
        for natural_language in language_modules[language].vocabulary:
            schemes[natural_language] = CustomCommandScheme('0x409') #todo fix
            for term_pattern in language_modules[language].vocabulary[natural_language]:
                for term in language_modules[language].vocabulary[natural_language][term_pattern].generate_terms():
                    for environment in environment_modules:
                        print environment
                        if not environment in schemes[natural_language].command_sets:
                            schemes[natural_language].command_sets[environment] = CommandSet('application', environment)
                        schemes[natural_language].command_sets[environment].commands.append(Command(term, 'devtoolsthatlisten', '', 'ns-eclipse-cmd.xml', 'some pattern'))
                        

    #TODO hack
    schemes[natural_language].command_sets = schemes[natural_language].command_sets.values()
    for natural_language in schemes:            
        f = open('''c:\\users\\ibrahimelfar\\''' + natural_language + '-naturallyspeaking.xml', 'w')
        print loader.render_to_string('naturallyspeaking.xml', django.template.Context({'scheme': schemes[natural_language]}))
        f.write(loader.render_to_string('naturallyspeaking.xml', django.template.Context({'scheme': schemes[natural_language]})))
        f.flush()
        f.close()
